import sys
fileIn=open(sys.argv[1])
fileOut=open(sys.argv[2],'w')
count=0
ind=int(sys.argv[3])
for line in fileIn.readlines():
	spl=line.strip().split(",")
	count+=1
	if spl[len(spl)-ind]=="1" and count>1:
		fileOut.write("\n")
	fileOut.write(spl[len(spl)-ind]+"\t"+"\t".join(spl)+"\n")
fileOut.close()
fileIn.close()
